package com.common.www.repository.tabulation;

import org.springframework.boot.base.jpa.repository.support.ExtendedRepository;
import com.common.www.bean.entity.tabulation.InnerSummary;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;



@Repository
public interface InnerSummaryRepository extends ExtendedRepository<InnerSummary, Long> {

    /**
     * 查询标底
     * @param projectId
     * @return
     */
    @Query(value = "SELECT * FROM inner_summary WHERE flag = 1 AND project_id = ? AND jie_duan = 1", nativeQuery = true)
    InnerSummary getByConditionJieDuanOne(Long projectId);

    /**
     * 查询实施标底
     * @param projectId
     * @return
     */
    @Query(value = "SELECT * FROM inner_summary WHERE flag = 1 AND project_id = ? AND jie_duan = 7", nativeQuery = true)
    InnerSummary getByConditionJieDuanSeven(Long projectId);


    /**
     * 按供应商查询
     * @param projectId
     * @param biddingCompanyId
     * @param jieDuan
     * @return
     */
    @Query(value = "SELECT * FROM inner_summary WHERE flag = 1 AND project_id = ? AND bidding_company_id = ? AND jie_duan = ? ", nativeQuery = true)
    InnerSummary getByConditionJieDuanTemp(Long projectId,Long biddingCompanyId,Integer jieDuan);

    /**
     * 按项目和阶段删除
     * @param projectId
     * @param jieDuan 1、7
     * @return
     */
    @Modifying
    @Transactional
    int deleteByProjectIdAndJieDuan(Long projectId,Integer jieDuan);

    /**
     * 按阶段、项目、供应商删除
     * @param projectId
     * @param jieDuan
     * @param biddingCompanyId
     * @return
     */
    @Modifying
    @Transactional
    int deleteByProjectIdAndJieDuanAndBiddingCompanyId(Long projectId,Integer jieDuan,Long biddingCompanyId);


}
